<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let longList = [
        { userName: 'admin', password: 'admin321' },
        { userName: 'zhangsan', password: 'zs321' },
        { userName: 'lisi', password: 'ls321' },
        { userName: 'yyqx', password: 'yyqx321' },
      ]
      let userInfo = {
        token1: {
          city: '杭州',
          money: '1000w',
          sex: '女',
          userName: 'admin',
          password: 'admin321',
        },
        token2: {
          city: '北京',
          money: '1100w',
          sex: '女',
          userName: 'zhangsan',
          password: 'zs321',
        },
        token3: {
          city: '北京',
          money: '800w',
          sex: '男',
          userName: 'lisi',
          password: 'ls321',
        },
        token4: {
          city: '天津',
          money: '600w',
          sex: '男',
          userName: 'yyqx',
          password: 'yyqx321',
        },
      }
      let time = 0
      function yyx() {
        let user = prompt('请输入用户名')
        let psd = prompt('请输入密码')
        for (let k in longList) {
          if (user === longList[k].userName && psd === longList[k].password) {
            time++
            break
          }
        }
        if (time > 0) {
          //1-4的随机数
          let num = Math.floor(Math.random() * longList.length) + 1
          let token = 'token'
          token += num
          // console.log(token)
          alert(`登录成功显示用户信息为
        city:${userInfo[token].city}
        money:${userInfo[token].money}
        sex:${userInfo[token].sex}
        userName:${userInfo[token].userName}`)
          // alert('成功')
        }
      }
      yyx()
      if (time <= 0) {
        alert('失败')
        let regist = +prompt(`
          登陆失败
          1.注册
            2.退出`)
        switch (regist) {
          case 1:
            user = prompt('请输入用户名')
            psd = prompt('请输入用户密码')
            longList.push({ userName: user, password: psd })
            //打印
            // console.log(longList)
            alert('您已注册成功直接去登录')
            //登录 封装函数？？？？
            yyx()
            for (let k in longList) {
              if (
                user !== longList[k].userName ||
                psd !== longList[k].password
              ) {
                alert('没机会了')
                break
              }
            }
            break
          case 2:
            break
          default:
            break
        }
      }
    </script>
  </body>
</html>
